package cate.game.role.farm.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBFarm;
import cate.game.role.farm.PlayTimes;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "副本挑战扫荡次数购买请求")
@OperationSetter(value = GDOperation.PLAY_TIMES_BUY, sub = "funcId")
public class PlayTimesBuyReq implements MsgInput {
    @NoteField(value = "功能ID")
    public int funcId;

    @NoteField(value = "购买次数")
    public int num;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        EcResult<PlayTimes> r = game.farm.playTimesHandler.buyTimes(cc.getRole(), funcId, num);
        if(!r.ok()){
            game.notice.message(cc.getRole(), r.message);
            return;
        }
        game.notice.message(cc.getRole(), "购买成功");
        cc.sendNow(new PlayTimesBuyResp(funcId, r.data));
        cc.getRole().getHistory().action.playTimesBuy(funcId);
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBFarm.PLAY_TIMES_BUY_REQ;
    }
}
